package com.winbomb.kingcard.base.anim.impl;

import com.winbomb.kingcard.Assets;
import com.winbomb.kingcard.IGameLogic;
import com.winbomb.kingcard.base.GameLogic;
import com.winbomb.kingcard.base.anim.IPlayable;
import com.winbomb.kingcard.base.anim.SimpleAnimation;
import com.winbomb.kingcard.framework.Graphics;

/**
 * 战斗结束后胜利和失败的动画
 * 
 * @author winbomb
 * 
 */
public class WinLoseAnim implements IPlayable {

	private SimpleAnimation anim;
	private Graphics g;
	private boolean isUpWin;

	/**
	 * 
	 * @param game
	 * @param isUpWin
	 *            是上面的胜利了,还是下面的胜利了(决定绘制胜利的地方)
	 */
	public WinLoseAnim(IGameLogic game, boolean isUpWin) {
		anim = new SimpleAnimation();
		anim.setDuration(180);
		anim.setFrameCount(6);
		anim.setFrameInterval(30);

		this.g = ((GameLogic) game).getRender().getGraphics();
		this.isUpWin = isUpWin;
	}

	@Override
	public boolean play(float dt) {

		if (!anim.hasFinished()) {

			int frameNum = anim.getCurrFrame();
			g.drawPixmap(Assets.anim_victory_defeated, 135, (isUpWin) ? 60 : 155, 230 * frameNum, 0, 230, 106);
			g.drawPixmap(Assets.anim_victory_defeated, 135, (isUpWin) ? 155 : 60, 230 * frameNum, 106, 230, 106);

			anim.step(dt);

			return false;
		}

		return true;
	}

}
